package api

import (
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
	"house/api/handler"
	"house/api/middleware"
	"house/consts"
)

func LoadRouters(r *gin.Engine) {
	r.Use(middleware.Cors())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register) //注册
			user.POST("/login", handler.Login)       //登录
			user.Use(gojwt.JWTAuth(consts.Jwt_KEY))
			user.POST("/refreshToken", handler.RefreshToken) //刷新token
		}
		house := api.Group("/house")
		{
			house.Use(gojwt.JWTAuth(consts.Jwt_KEY))
			house.POST("/addHouse", handler.AddHouse)       //发布房源
			house.GET("/listHouse", handler.ListHouse)      //房源列表
			house.GET("/detail", handler.Detail)            //房源详情
			house.POST("/updateHouse", handler.UpdateHouse) //房源修改
		}
		reservation := api.Group("/reservation")
		{
			reservation.Use(gojwt.JWTAuth(consts.Jwt_KEY))
			reservation.POST("/addReservation", handler.AddReservation)       //用户预约
			reservation.POST("/deleteReservation", handler.DeleteReservation) //取消房源预约
		}
		order := api.Group("/order")
		{
			order.Use(gojwt.JWTAuth(consts.Jwt_KEY))
			order.POST("/addOrder", handler.AddOrder)   //用户下单
			order.POST("/upLoadPay", handler.UpLoadPay) //上传凭证信息
		}
		admin := api.Group("/admin")
		{
			admin.Use(gojwt.JWTAuth(consts.Jwt_KEY))
			admin.GET("/listOrder", handler.ListOrder)      //管理员查看订单
			admin.POST("/updateOrder", handler.UpdateOrder) //管理员查看订单
		}
		file := api.Group("/file")
		{
			file.Use(gojwt.JWTAuth(consts.Jwt_KEY))
			file.POST("/addImg", handler.AddImg)     //上传图片
			file.POST("/addVideo", handler.AddVideo) //上传视频
		}
		chat := api.Group("/chat")
		{
			chat.Use(gojwt.JWTAuth(consts.Jwt_KEY))
			chat.GET("/ws", handler.Chat) //一对一私聊
		}
	}
}
